package middleware

import (
	"go-web-scaffold/api"
	"go-web-scaffold/tws"
	"time"

	"github.com/gin-gonic/gin"
)

func RequestLogger() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		d := time.Now().Format("2006-01-02 15:04:05")
		tws.WriteText(api.LoggerInfo{
			Url:        ctx.Request.RequestURI,
			Method:     ctx.Request.Method,
			ClientIP:   ctx.ClientIP(),
			StatusCode: "200",
			Date:       d,
		})
		ctx.Next()
	}
}
